<?php
namespace app\admin\controller;

/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2019/10/10
 * Time: 21:57
 */

use app\common\model\AfficheTypeModel;
use think\Lang;

class Tagsetup extends AdminControl
{
    protected $afficheType;

     /**
     * @description:
     */
    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/affiche.lang.php');
    }

    public function setting()
    {
        $afficheType = model('afficheTypeModel');

        if (!empty(input('param.search_brand_name'))) {
            $condition['name'] = array('like', "%" . input('param.search_brand_name') . "%");
        }
        $condition['id'] = ['gt',0];
//        $list =  $afficheType->getAfficheTypeList([], 7);
        $list = db('tagsetup')->where($condition)->select();
        $this->assign('list', $list);
//        $this->assign('show_page', $afficheType->page_info->render());
        $this->assign('search_brand_name', trim(input('param.search_brand_name')));
        $this->setAdminCurItem('index');
        return $this->fetch('index');
    }

    public function add()
    {
        $brand_array = [
            'status' => 1
        ];
        $this->assign('brand_array',$brand_array);
        $this->setAdminCurItem('add');
        return $this->fetch('add');
    }

    /**
     * @description: 编辑 @MrLiu
     */
    public function edit()
    {
        $id = intval(input('param.id'));

        $data = db('tagsetup')->where(['id'=>$id])->find();
        $this->assign('data', $data);
        $brand_array = [
            'status' => $data['status']
        ];
        $this->assign('brand_array',$brand_array);
        $this->setAdminCurItem('edit');
        return $this->fetch('add');
    }

    /**
     * @description: 更新或者保存 @MrLiu
     */
    public function save()
    {
        $id = intval(input('param.id'));
        if(empty($id)){
            //新增
            $data = array(
                'content' =>   input('param.name'),
                'status' =>   input('param.status'),
                'time' => time()
            );
            
            $status = db('tagsetup')->insertGetId($data);
            if ($status>=0) {
                dsLayerOpenSuccess('新增成功');
            } else {
                $this->error('新增失败');
            }
        }else{
            //编辑
            $data = array(
                'content' =>   input('param.name'),
                'status' =>   input('param.status'),
            );
            $status = db('tagsetup')->where(['id'=>$id])->update($data);
            if ($status>=0) {
                dsLayerOpenSuccess('编辑成功');
            } else {
                $this->error('编辑失败');
            }

        }

    }


    /**
     * @description: 删除操作  @MrLiu
     */
    public function cancels()
    {
        $id = intval(input('param.id'));
        
        $status = db('goodsproject_class')->where(['id'=>$id])->delete();
        if ($status === false) {
            ds_json_encode(10001, '删除失败');
        }
//        $this->log(lang('ds_add') . lang('affiche_type_index_class') . '[ID:' . $id . ']', 1);
        ds_json_encode(10000, '删除成功');
    }



    /**
     * @description:   @MrLiu
     * @return array
     */
    protected function getAdminItemList()
    {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => lang('ds_manage'),
                'url' => url('Tagsetup/setting')
            ),
        );

        if (request()->action() == 'add' || request()->action() == 'setting') {
            $menu_array[] = [
                'name' => 'add',
                'text' => lang('ds_new'),
                'url' => "javascript:dsLayerOpen('" . url('Tagsetup/add') . "','" . '新增' . "')",
            ];
        }

        if (request()->action() == 'edit') {
            $menu_array[] = array(
                'name' => 'edit',
                'text' => lang('ds_edit'),
                'url' => 'javascript:void(0)'
            );
        }
        return $menu_array;
    }
}